/**
 * 详情对话框
 */
var ZxHuopinInfoDlg = {
    data: {
        code: "",
        name: "",
        zhujima: "",
        btyZxKemuId: "",
        btyZxKemuIdView: "",
        status: "",
        statusView: "",
        delFlag: "",
        createUser: "",
        createUserName: "",
        createTime: "",
        updateUser: "",
        updateUserName: "",
        updateTime: "",
        company: "",
        companyView: "",
        srcType: "",
        srcValue: ""
    }
};

layui.use(['form', 'admin', 'ax','layer','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;
    var formSelects = layui.formSelects;


    //初始化供货商
    $("#ghs").html("");
    var languageAjax = new $ax(Feng.ctxPath + "/btyBxda/getZxList");
    var languageResult = languageAjax.start();
    $.each(languageResult.data, function (index, val) {
        $("#ghs").append("<option value='" + val.value + "'>" + val.label+ "</option>");
    });
    formSelects.render('ghs');

    formSelects.on('ghs', function(id, vals, val, isAdd, isDisabled){
        //id:           点击select的id
        //vals:         当前select已选中的值
        //val:          当前select点击的值
        //isAdd:        当前操作选中or取消
        //isDisabled:   当前选项是否是disabled
        var dm=formSelects.value('ghs', 'nameStr');
        $("#ghsNames").val(dm);
    }, true);

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/dgdzxHuopin/detail?btyZxHuopinId=" + Feng.getUrlParam("btyZxHuopinId"));
    var result = ajax.start();
    if(result.data.pName!=''){
    $("#zxHpFlName").val(result.data.pName);
    }


    form.val('zxHuopinForm', result.data);
    //回填供货商
    formSelects.value('ghs', (result.data.ghsIds).split(","));
    //formSelects.value('ghs', (result.data.ghsIds).split(","),true);





    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/dgdzxHuopin/saveGhs", function (data) {
            if(data.code==1){
                Feng.error("修改失败!" + data.message);
                return;
            }
            Feng.success("更新成功！");
            closePage();
            //window.location.href = Feng.ctxPath + '/dgdzxHuopin'
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
        return false;
    });

    function closePage(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    //返回按钮
    $("#backupPage").click(function () {
        closePage();
    });




});